package raytracer.objects;

import raytracer.math.Vector3d;
import raytracer.misc.Ray;


/**
 * 
 * @author Thorsten Roth
 * @version 11.10.2006
 */
public class Plane extends ThreeDObject {

	private Vector3d normal;
	private double distance;
	
	public Plane(Vector3d normal, double distance) {
		super();
		this.normal=normal;
		normal.normalize();
		this.distance=distance;
	}
	
	public Double intersect(Ray ray, Vector3d intersectionPoint, Vector3d intersectionNormal) {
		if (intersectionNormal!=null) {
			intersectionNormal.set(normal);
		}
		Vector3d direction=new Vector3d(ray.getDirection());
		Vector3d origin=new Vector3d(ray.getOrigin());
		
		double t=(-(normal.dot(origin)+distance))/(normal.dot(direction));
		if (t>0) {
			if (intersectionPoint!=null) {
				intersectionPoint.x=origin.x+t*direction.x;
				intersectionPoint.y=origin.y+t*direction.y;
				intersectionPoint.z=origin.z+t*direction.z;
			}
			return t;
		}
		else {
			return null;
		}
		
	}

	@Override
	public double getMaxX() {
		return 0;
	}

	@Override
	public double getMaxY() {
		return 0;
	}

	@Override
	public double getMaxZ() {
		return 0;
	}

	@Override
	public double getMinX() {
		return 0;
	}

	@Override
	public double getMinY() {
		return 0;
	}

	@Override
	public double getMinZ() {
		return 0;
	}

	@Override
	public boolean isInfinite() {
		return true;
	}
	
}
